package com.hqyj.ssm_project.utils;

import java.util.List;

/**
 * @author cjgong
 * @date 2022/4/1415:51
 * @description: TODO
 */
public class PageUtil<T> {
    // 当前页需要展示的数据
    private List<T>  dataList;
    // 表里的总记录数
    private int recordNum;
    // 分页单位
    private int pageUnit=Ssm_Project_Constant.PAGE_UNIT;
    //  当前页号
    private int currentNum;

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public int getRecordNum() {
        return recordNum;
    }

    public void setRecordNum(int recordNum) {
        this.recordNum = recordNum;
    }

    public int getPageUnit() {
        return pageUnit;
    }

    public void setPageUnit(int pageUnit) {
        this.pageUnit = pageUnit;
    }

    public int getCurrentNum() {
        return currentNum;
    }

    public void setCurrentNum(int currentNum) {
        this.currentNum = currentNum;
    }

    // 获取总页数
    public int getTotalPageNumber(){
        int result=(int)Math.ceil(this.recordNum*1.0/this.pageUnit);
        return result;
    }
    // 获取上一页页号
    public int getPrePageNumber(){
        int result=this.currentNum-1;
        if(result<=1){
            result=1;
        }
        return result;
    }
    // 获取下一页的页号
    public int getNextPageNumber(){
        int result=this.currentNum+1;
        if(result>=getTotalPageNumber()){
            result=getTotalPageNumber();
        }
        return result;
    }
}
